use std::any::Any;
use std::rc::Rc;
use std::sync::Arc;
use rpc::{RpcContext, RpcFilter, RpcResult};
use rpc::error::RpcError;

#[test]
fn mut_test()-> RpcResult<()> {
    let mut rpc_context = RpcContext::test_context_with_codec_type("json");
    test1(&mut rpc_context);
    test2(&mut rpc_context);

    let fs: Vec<Box<dyn RpcFilter>> = vec![Box::new(RpcFilter1), Box::new(RpcFilter2)];
    for filter in fs.iter() {
        filter.after(&mut rpc_context, &mut Box::new(11))?;
    }

    let fs2 :Rc<Vec<Box<dyn RpcFilter>>> = Rc::new(vec![Box::new(RpcFilter1), Box::new(RpcFilter2)]);
    for filter in fs2.iter() {
        filter.after(&mut rpc_context, &mut Box::new(11))?;
    }

    let fs2 :Arc<Vec<Box<dyn RpcFilter>>> = Arc::new(vec![Box::new(RpcFilter1), Box::new(RpcFilter2)]);
    for filter in fs2.iter() {
        filter.after(&mut rpc_context, &mut Box::new(11))?;
    }
    Ok(())
}

fn test1(_context: &RpcContext) {

}

fn test2(_context: &RpcContext) {

}

struct RpcFilter1;
impl RpcFilter for RpcFilter1 {
    fn after(&self, _rpc_channel: &mut RpcContext, _data: &mut dyn Any) -> Result<(), RpcError> {
        Ok(())
    }
}

struct RpcFilter2;
impl RpcFilter for RpcFilter2 {
    fn after(&self, _rpc_channel: &mut RpcContext, _data: &mut dyn Any) -> Result<(), RpcError> {
        Ok(())
    }
}